#include <chrono>
#include <memory>

#include <functional>
#include <string>

#include "rclcpp/rclcpp.hpp"
#include "bs_complex/msg/complex_num.hpp"

using namespace std::chrono_literals;

/* This example creates a subclass of Node and uses std::bind() to register a
* member function as a callback from the timer. */

class ComplexNumPublisher : public rclcpp::Node
{
public:
  ComplexNumPublisher()
  : Node("complex_publisher")
  {
    publisher_ = this->create_publisher<bs_complex::msg::ComplexNum>("complex_num", 10);
    timer_ = this->create_wall_timer(
      500ms, std::bind(&ComplexNumPublisher::timer_callback, this)
    );
  }

private:
  rclcpp::TimerBase::SharedPtr timer_;
  rclcpp::Publisher<bs_complex::msg::ComplexNum>::SharedPtr publisher_;


  void timer_callback()
  {
    auto message = bs_complex::msg::ComplexNum();
    message.re = 1.0;
    message.im = 1.0;
    RCLCPP_INFO(this->get_logger(), "Publishing: re=%.3f im=%.3f", message.re, message.im);
    publisher_->publish(message);
  }
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<ComplexNumPublisher>());
  rclcpp::shutdown();
  return 0;
}